var Events = require('ym-Events')

cc.Class({
    extends: cc.Component,

    properties: {
    },

    start () {
        if(CC_WECHATGAME){
            var rect = wx.getMenuButtonBoundingClientRect()
            var systemInfo = wx.getSystemInfoSync();
            var ccsize = cc.winSize;
            var x = rect.left / systemInfo.screenWidth * ccsize.width;
            var y = rect.top / systemInfo.screenHeight * ccsize.height;
            var height = rect.height / systemInfo.screenHeight * ccsize.height;
            this.node.getChildByName('menu').setPosition(cc.v2(x,-y-height - 10))
        }
        Events.on('backOtherApp',this.onClickShow,this)
    },
    onDestroy(){
        Events.off(this)
    },
    onClickShow(){
        this.node.getChildByName('menu').active = false;
        this.node.getChildByName('layout').active = true;
        Events.emit('wechatMenuOpen')
    },
    onClickClose(event){
        this.node.getChildByName('menu').active = true;
        this.node.getChildByName('layout').active = false;
        Events.emit('wechatMenuClose')
    }
});
